<?php

namespace App\Http\Controllers\Admin;

use App\MemberLog;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Maatwebsite\Excel\Facades\Excel;

class CaiwuController extends Controller
{
    public function index(){

        return view('admin.caiwu.index');
    }
    //ajax
    public function ajax(Request $request)
    {
        $list = MemberLog::paginate(10)->toArray();
        return $this->page_json_render($list);
    }
    public function export(){
        $list=MemberLog::all();
        $cellData =[['id','昵称','顶级订单量','顶级提成','直推订单','直推提成','总提成']];
        foreach ($list as &$v){
            $temp_data=[
                $v->id,
                $v->nickname,
                $v->first_order_num,
                $v->first_money,
                $v->order_num,
                $v->money,
                $v->first_order_money+$v->money,
            ];
            $cellData[]=$temp_data;
        }
        Excel::create('财务报表',function($excel) use ($cellData){
            $excel->sheet('orders', function($sheet) use ($cellData){
                $sheet->rows($cellData);
            });
        })->export('xlsx');
    }
}
